What does FileShare enum do in file operations?
What does FileShare enum do in file operations? with example
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
01-Jun-2025The
FileShareenum in .NET specifies the level of access otherFileStreamobjects have to a file that is already open. It controls how multiple processes or threads can read, write, or delete a file simultaneously.Namespace
Used in
When opening a file, such as with
FileStream,File.Open, etc.Common Syntax
FileShareEnum ValuesNoneReadWriteReadWriteDeleteInheritableExample Use Case
Why It Matters
If you try to open a file that another process has locked with
FileShare.None, your code will throw anIOException. Choosing the appropriateFileSharevalue prevents this.